package org.inspursc.s0517.health.evaluation.dao;

import org.inspursc.s0517.health.evaluation.entity.Customer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;



import java.util.List;

/**
 * @author B_Dream
 * @date 2018/5/22 9:37
 */
public interface CustomerDao extends JpaRepository<Customer, Integer>, JpaSpecificationExecutor<Customer> {


    /**
     * 根据身份证Id查找被评估人
     *
     * @param idNumber
     * @return
     */
    Customer findByIdNumber(String idNumber);

    /**
     * 根据组织机构Id查找被评估人
     *
     * @param orId
     * @return
     */
    List<Customer> findAllByOrganizationId(Integer orId);

    /**
     * 根据评估师Id查找用户Id
     *
     * @param appId
     * @return
     */
    List<Customer> findAllByAppraiserId(Integer appId);

    /**
     * 根据身份Id删除被评估人
     *
     * @param idNumber
     * @return
     */
    boolean deleteCustomerByIdNumber(String idNumber);

    List<Customer> findByAgeBetween(int i, int i1);
    List<Customer> findByAgeBetweenAndOrganizationId(Integer i, Integer j,Integer id);


    @Query("SELECT SUM( CASE WHEN t.age <60 THEN 1 ELSE 0 END  ) ,SUM( CASE WHEN t.age >=60 and t.age<=70 THEN 1 ELSE 0 END  ),SUM( CASE WHEN t.age >=70 and t.age<=80 THEN 1 ELSE 0 END  ),SUM( CASE WHEN t.age >=80 and t.age<=90 THEN 1 ELSE 0 END  ),SUM( CASE WHEN  t.age>90 THEN 1 ELSE 0 END  )FROM t_customer t")
    List<Long> getCharts();



}
